// 引入mockjs
import Mock from "mockjs";

// 获取 mock.Random 对象
const Random = Mock.Random;

// 使用mockjs模拟数据
let tableList: any[] = [];

for (let i = 0; i < 10; i++) {
  let newObject = {
    id: Random.guid(), // 获取全局唯一标识符
    account: `account-${i + 123}`,
    password: `${i}-*****`,
    address: `福州路10${i}号`,
  };
  tableList.push(newObject);
}

/** get请求
 * 获取用户列表
 */
Mock.mock("/api/page", "get", () => {
  return {
    code: "0",
    message: "success",
    data: {
      total: 10,
      list: tableList,
    },
  };
});

/** post请求添加表格数据 */
Mock.mock("/api/add", "post", (params) => {
  let newData = JSON.parse(params.body);
  newData.id = Random.guid();
  tableList.push(newData);
  return {
    code: "0",
    message: "success",
    data: {
      total: 100,
      list: tableList,
    },
  };
});
